package lib.gt.map;

import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public abstract class AbsItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	
	private static final String TAG = "AbsItemizedOverlay";
	
	private OnTapListener mOnTapListener;

	public AbsItemizedOverlay(Drawable d) {
		super(boundCenter(d));
	}

	@Override
	protected boolean onTap(int index) {
		if(mOnTapListener != null) {
			boolean interrupt = mOnTapListener.onTap(index);
			if(interrupt) {
				return true;
			}
		}
		return super.onTap(index);
	}
	
	@Override
	public boolean onTap(GeoPoint point, MapView mapView) {
		if(mOnTapListener != null) {
			boolean interrupt = mOnTapListener.onTap(point, mapView);
			if(interrupt) {
				return true;
			}
		}
		return super.onTap(point, mapView);
	}

	public void release() {
		mOnTapListener = null;
	}
	
	public void setOnTapListener(OnTapListener l) {
		mOnTapListener = l;
	}

	public static interface OnTapListener {
		/**
		 * 返回值決定是否要攔截父類的onTop(int index)方法.
		 * @param index
		 * @return true表示攔截, false表示不攔截
		 */
		boolean onTap(int index);
		
		/**
		 * 返回值決定是否要攔截父類的onTop(GeoPoint point, MapView mapView)方法.
		 * @param point
		 * @param mapView
		 * @return true表示攔截, false表示不攔截
		 */
		boolean onTap(GeoPoint point, MapView mapView);
	}
}
